/*******************************************************************************
 * -------
 *   Copyright 2011 @ Fluid India Consultancy
 *   All Rights Reserved
 * -------
 ******************************************************************************/
package org.fluidindia.security.dao.impl;

import java.util.List;

import org.fluidindia.core.dao.AbstractDao;
import org.fluidindia.security.dao.IUserDao;
import org.fluidindia.security.domain.User;
import org.fluidindia.security.mapper.UserMapper;

/**
 * Provides an implementation for {@link IUserDao} for a Database driven user-store.
 * 
 * @author Kapil Viren Ahuja
 *
 */
public class UserDao extends AbstractDao<User> implements IUserDao
{
    /**
     * 
     * @See {@link IUserDao#getUser(String, String)}
     * 
     */
    public User getUser(String username, String password)
    {
        String sql = super.getQuery("ad_users", "getUser"); 
        List<User> users = super.query(sql, new UserMapper(), username, password);
        
        if (users.size() == 0)
        {
            return new User();
        }
        else if (users.size() == 1)
        {
            return users.get(0);
        }
        else
        {
            //throw exception - not possible to have two users with same user name and password.
            return null;
        }
    }
}
